﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Mimoza.GUI;

namespace Mimoza.RdpPlugin
{
    public partial class DisplayPage : Mimoza.GUI.WizardPage
    {
        private RdpData m_data;
        public DisplayPage()
        {
            InitializeComponent();

            comboBoxColor.SelectedIndex = comboBoxColor.Items.Count - 1;
        }

        override public void Init()
        {
            m_data = this.Wizard.UserData as RdpData;

            trackBarResolution.Value = (int)m_data.Resolution;
            trackBarResolution_Scroll(null, null);

            comboBoxColor.SelectedIndex = (int)m_data.ColorDepth;

            checkBoxDisplayInBar.Checked = m_data.IsDisplayConnectionBar;

            this.trackBarResolution.ValueChanged += new System.EventHandler(this.trackBarResolution_ValueChanged);
            this.trackBarResolution.Scroll += new System.EventHandler(this.trackBarResolution_Scroll);
            this.comboBoxColor.SelectedIndexChanged += new System.EventHandler(this.comboBoxColor_SelectedIndexChanged);
            this.checkBoxDisplayInBar.CheckedChanged += new System.EventHandler(this.checkBoxDisplayInBar_CheckedChanged);
        }

        override public bool Try2LeavePage(WizardPageLeavingDirection direction)
        {
            if (direction == WizardPageLeavingDirection.Back)
            {
                return true;
            }

            m_data.Resolution = (Resolution)trackBarResolution.Value;
            m_data.ColorDepth = (ColorDepth)comboBoxColor.SelectedIndex;
            m_data.IsDisplayConnectionBar = checkBoxDisplayInBar.Checked;

            return true;
        }

        private void trackBarResolution_Scroll(object sender, EventArgs e)
        {
            textBoxResolution.Text = GetResolutionString((Resolution)trackBarResolution.Value);
        }

        string GetResolutionString(Resolution res)
        {
            string resStr;
            switch (res)
            {
                case Resolution.Res640x480:
                    resStr = Resource.Resolution1;
                    break;
                case Resolution.Res800x600:
                    resStr = Resource.Resolution2;
                    break;
                case Resolution.Res1024x768:
                    resStr = Resource.Resolution3;
                    break;
                case Resolution.Res1280x800:
                    resStr = Resource.Resolution4;
                    break;
                case Resolution.Res1280x720:
                    resStr = Resource.Resolution5;
                    break;
                case Resolution.Res1280x768:
                    resStr = Resource.Resolution6;
                    break;
                default:
                    resStr = Resource.ResolutionFullScreen;
                    break;
            }

            return resStr;
        }

        private void trackBarResolution_ValueChanged(object sender, EventArgs e)
        {
            this.RaiseOnPageModified();
        }

        private void comboBoxColor_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.RaiseOnPageModified();
        }

        private void checkBoxDisplayInBar_CheckedChanged(object sender, EventArgs e)
        {
            this.RaiseOnPageModified();
        }
    }
}
